﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Shop.Backstage.Models;
using Shop.Backstage.Services;
using Shop.Backstage.Repositories;
using Shop.Backstage.WebProxy;
using Shop.Backstage.Filters;

namespace Shop.Backstage.Controllers
{
    public class HuiController : Controller
    {
        /// <summary>
        /// 管理员登陆页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            return View(new AdminInfo());
        }
        /// <summary>
        /// 管理员登陆
        /// </summary>
        /// <param name="admininfo"></param>
        /// <param name="IMGTXT"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult login(AdminInfo admininfo, string IMGTXT)
        {
            if (!ModelState.IsValid)
            {
                return View(admininfo);
            }
            string rndcodetxt = Session["rndcode"].ToString();

            if (IMGTXT == "")
            {
                ViewBag.Miss = "请输入验证码!";
                return View(admininfo);
            }
            else if (!rndcodetxt.Equals(IMGTXT.ToLower()))
            {
                ViewBag.Miss = "验证码错误!请确认后输入";
                return View(admininfo);
            }
            login service = new login();
            string ifdb = service.IfDblogin(admininfo);

            if (ifdb.Equals("账号或密码错误!"))
            {
                ViewBag.Miss = ifdb;
                return View(admininfo);
            }
            else
            {
                return Redirect("index");
            }
        }
        /// <summary>
        /// 后台管理主页
        /// </summary>
        /// <returns></returns>
        [AdminLogin]
        public ActionResult index()
        {
            AdminInfo admininfo = AdminState.GetAdminState();
            ViewBag.ss = admininfo.AName;
            return View(admininfo);
        }
        /// <summary>
        /// 验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult YanZhengMa()
        {
            return File(Shop.Core.Common.CheckCode.ProcessRequest(), "image/gif");
        }
        public ActionResult welcome()
        {
            return View();
        }
    }
}